package com.itheima.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.vo.CheckGroupVO;
import com.itheima.health.vo.SetmealVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface SetmealMapper extends BaseMapper<Setmeal> {
    @Insert("insert into t_setmeal_checkgroup values (#{sid},#{gid})")
    void addSetmealAndGroup(@Param("sid") Integer sid,@Param("gid") Integer gid);

    @Select("select CHECKGROUP_ID from t_setmeal_checkgroup where SETMEAL_ID = #{id}")
    int[] findGroupId(@Param("id") Integer id);

    @Select("select IMG from t_setmeal where id = #{id}")
    String findImgUrl(@Param("id") Integer id);

    @Delete("delete from t_setmeal_checkgroup where SETMEAL_ID = #{sid}")
    void deleteSetmealAndGroupById(@Param("sid") Integer sid);

    @Select("select name,remark,sex,age,img from t_setmeal where id = #{id}")
    SetmealVO findSetmealById(@Param("id") int id);

    @Select("select tc.id,tc.name,tc.remark from t_checkgroup tc join t_setmeal_checkgroup tsc on" +
            " tsc.CHECKGROUP_ID = tc.ID where tsc.SETMEAL_ID=#{id}")
    List<CheckGroupVO> findCheckgroupsById(@Param("id") int id);
}
